import bpy
import numpy as np

import 全局控制.Node.节点和插座基类.bl_节点基类 as 基类
import Core.bl_维度转换 as 维度转换
import Core.bl_矩阵变换 as 矩阵转换

from itertools import chain



import 节点.Core.bl_Mesh as 网格操作


#engineLib.flexCAPI.f_创建物体变换节点.restype = ctypes.c_bool






 

class C_Node_set应用矩阵(基类.C_SN_基类):
	bl_dname = 'bl_node_物体属性set'
	bl_label = '应用矩阵'
	
	def init(self, context):
		super(C_Node_set应用矩阵, self).f_init(context)
		self.inputs.new('C_NodeSocket_物体', name='对象')
		self.inputs.new('C_插座_List_i', name='应用类型')

	def f_update(self, 是否向下传递=False, input插座=None):
		objs = self.inputs['对象'].f_getData()
		#print('obj.scale = ', objs)
		for obj in objs :
			矩阵转换.f_网格变换_缩放(obj, obj.matrix_world)
			
		super(C_Node_set应用矩阵, self).f_update(是否向下传递, input插座)

class C_NODE_MENU_物体属性set应用矩阵(bpy.types.Operator):
	bl_idname = 'node.global_node_set_obj_apply_translation'
	bl_label = '应用矩阵'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		bpy.ops.node.add_node(type='C_Node_set应用矩阵', use_transform=True)
		return {'FINISHED'}

















'''class C_Node_物体变换(基类.C_Node_基类):
	bl_dname = 'bl_node_物体变换'
	bl_label = '物体变换'
	
	def init(self, context):
		super(C_Node_物体变换, self).f_init(context)
		self.inputs.new('C_Socket_物体集', name='物体集')
		self.inputs.new('C_Socket_矩阵4X4', name='矩阵4X4')
		self.f_toCPP(self.id_data)

	def f_toCPP(self, tree):
		engineLib.flexCAPI.f_创建物体变换节点(ctypes.c_wchar_p(tree.name), ctypes.c_wchar_p(self.name), self.f_getPyObject(tree));
	
	def f_update(self):
		物体集 = self.inputs['物体集'].f_getData()
		矩阵4X4 = self.inputs['矩阵4X4'].f_getData()
		for obj in 物体集:
			
			pass

class C_NODE_MENU_物体变换(bpy.types.Operator):
	bl_idname = 'node.global_node_set_obj_translation'
	bl_label = '物体变换'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		bpy.ops.node.add_node(type='C_Node_物体变换', use_transform=True)
		return {'FINISHED'}
'''











class C_Node_网格变换(基类.C_Node_基类):
	bl_dname = 'bl_node_网格变换'
	bl_label = '网格变换'
	
	def init(self, context):
		super(C_Node_网格变换, self).f_init(context)
		self.inputs.new('C_Socket_网格', name='输入网格')
		网格操作.f_创建网格插座(self, False)
		self.outputs.new('C_Socket_网格', name='输出网格')
	

class C_NODE_MENU_网格变换(bpy.types.Operator):
	bl_idname = 'node.global_node_set_mesh_translation'
	bl_label = '网格变换'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		bpy.ops.node.add_node(type='C_Node_网格变换', use_transform=True)
		return {'FINISHED'}










classes = (
	C_Node_set应用矩阵,
	C_NODE_MENU_物体属性set应用矩阵,

	C_Node_网格变换,
	C_NODE_MENU_网格变换,

)

def register():
	for c in classes:
		bpy.utils.register_class(c)
		
def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)



